<h1>Activités</h1>

<?php echo link_to('Cumul hebdomadaire', 'activite/index?group=hebdo') ?>
&nbsp;
<?php echo link_to('Cumul quotidien', 'activite/index?group=quot') ?>


<?php
	// préparation tableau des suivis
	$cumuls = array();
	foreach ($activites as $activite) {
		if ($group == 'hebdo') {
			foreach ($activite->getCumulHebdo() as $week => $cumul) {
				if (!isset($cumuls[$week])) $cumuls[$week] = array();
				$cumuls[$week][$activite->getActId()] = $cumul;
			}
		} else {
			foreach ($activite->getCumulQuot() as $day => $cumul) {
				if (!isset($cumuls[$day])) $cumuls[$day] = array();
				$cumuls[$day][$activite->getActId()] = $cumul;
			}
		}
		foreach ($activite->getActivitesFils() as $fils) {
			if ($group == 'hebdo') {
				foreach ($fils->getCumulHebdo() as $week => $cumul) {
					if (!isset($cumuls[$week])) $cumuls[$week] = array();
					$cumuls[$week][$fils->getActId()] = $cumul;
				}
			} else {
				foreach ($fils->getCumulQuot() as $day => $cumul) {
					if (!isset($cumuls[$day])) $cumuls[$day] = array();
					$cumuls[$day][$fils->getActId()] = $cumul;
				}
			}
		}
	}
	ksort($cumuls);
	reset($cumuls);
	$week_min = key($cumuls);
	end($cumuls);
	$week_max = key($cumuls);
?>

<table class="liste_activite">
	<thead>
		<tr>
			<th/>
			<th>Activité</th>
			<th>Durée</th>
			<?php
				for ($w=$week_min; $w<=$week_max; $w++) {
					echo '<th>'. ($group == 'hebdo' ? 'S' : 'J') .".$w</th>\n";
				}
			?>
		</tr>
	</thead>
	<tbody>
		<?php 
		foreach ($activites as $activite) {
			$actif = ($activite->getActActif() == 1);
			echo '<tr>';
			echo '<td class="action">';
			echo link_to(image_tag('show.png'), 'activite/show?act_id='.$activite->getActId(), array('title' => 'Détail des pointages'));
			echo '</td>';
			
			echo '<td class="pere'.($actif ? ' actif' : '').'">'. link_to($activite->getActLibelle(), 'activite/start?act_id='.$activite->getActId(), array('class' => 'activite')) .'</td>';
			echo '<td>'. $activite->getCumulDuree() .'</td>';
			
			for ($w=$week_min; $w<=$week_max; $w++) {
				echo '<td>'. (isset($cumuls[$w][$activite->getActId()]) ? $cumuls[$w][$activite->getActId()] : '') .'</td>';
			}
			echo '</tr>';
		
			foreach ($activite->getActivitesFils() as $fils) {
				$actif = ($fils->getActActif() == 1);
				echo '<tr>';
				echo '<td class="action">';
				echo link_to(image_tag('show.png'), 'activite/show?act_id='.$fils->getActId(), array('title' => 'Détail des pointages'));
				echo '</td>';

				echo '<td class="fils'.($actif ? ' actif' : '').'">'. link_to($fils->getActLibelle(), 'activite/start?act_id='.$fils->getActId(), array('class' => 'activite')) .'</td>';
				echo '<td>'. $fils->getCumulDuree() .'</td>';

				for ($w=$week_min; $w<=$week_max; $w++) {
					echo '<td>'. (isset($cumuls[$w][$fils->getActId()]) ? $cumuls[$w][$fils->getActId()] : '') .'</td>';
				}
				echo '</tr>';
			}
		} 
		?>

		<tr>
			<td/>
			<td><?php echo link_to('Fin', 'activite/stop') ?></td>
			<td/>
			<?php
				for ($w=$week_min; $w<=$week_max; $w++) {
					echo "<td/>\n";
				}
			?>
		</tr>
	</tbody>
</table>

<?php echo link_to('Nouvelle activité', 'activite/new') ?>
